﻿using System;
using System.Windows;
using System.Windows.Controls;
using Moonwish.Foundation.ValueObjects;

namespace Moonwish.Foundation.Views.ValueObjects
{
    /// <summary>
    /// 值对象编辑对话框，by zhlin 2011-08-12
    /// </summary>
    public partial class ValueObjectDialog : ChildWindow
    {
        public event EventHandler ApplyOk;

        public ValueObjectDialog(ValueObject dataItem)
        {
            InitializeComponent();

            DataContext = dataItem;
        }

        public ValueObject ViewObject
        {
            get
            {
                return (ValueObject)DataContext;
            }
        }

        private void BtnOk_Click(object sender, RoutedEventArgs e)
        {
            if (ViewObject.Validate())
            {
                DialogResult = true;
            }
        }

        private void BtnApply_Click(object sender, RoutedEventArgs e)
        {
            if (ViewObject.Validate())
            {
                if (ApplyOk != null)
                {
                    ApplyOk(sender, e);
                }
            }
            
        }

        private void BtnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}

